package net.zhuike.novel.app.ui.adapter;
import android.content.Context;
import android.support.v4.content.ContextCompat;
import android.text.Spannable;
import android.text.SpannableString;
import android.text.style.ForegroundColorSpan;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;

import net.zhuike.novel.app.R;
import net.zhuike.novel.app.bean.RecommendBookList;
import net.zhuike.novel.app.bean.support.BookMark;
import net.zhuike.novel.app.common.OnRvItemClickListener;
import net.zhuike.novel.app.manager.SettingManager;
import net.zhuike.novel.app.ui.activity.ReadMenuActivity;
import net.zhuike.novel.app.ui.base.Constant;
import net.zhuike.novel.app.ui.utils.NoDoubleClickListener;

import java.util.List;

import framework.common.easyadpter.glide.GlideRoundTransform;
import framework.common.easyadpter.recyclerview.EasyRVAdapter;
import framework.common.easyadpter.recyclerview.EasyRVHolder;

/**
 * @author wq.
 * @date 17/6/22.
 */
public class RecommendBookListAdapter extends BaseAdapter {
    public List<RecommendBookList.RecommendBook> list;
    private Context context;
    private LayoutInflater flater;
    public RecommendBookListAdapter(Context context, List<RecommendBookList.RecommendBook> list) {
        this.context = context;
        this.list = list;
        this.flater = LayoutInflater.from(context);
    }

    @Override
    public int getCount() {
        // TODO Auto-generated method stub
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        // TODO Auto-generated method stub
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        // TODO Auto-generated method stub
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        // TODO Auto-generated method stub
        ViewHolder holder = null;
        if (convertView == null) {
            holder = new ViewHolder();
            convertView = flater.inflate(R.layout.item_book_detail_recommend_book_list, null);
            holder.tvBookListTitle = (TextView) convertView
                    .findViewById(R.id.tvBookListTitle);
            holder.tvBookAuthor = (TextView) convertView
                    .findViewById(R.id.tvBookAuthor);
            holder.tvBookListDesc = (TextView) convertView
                    .findViewById(R.id.tvBookListDesc);
            holder.ivBookListCover=(ImageView) convertView
                    .findViewById(R.id.ivBookListCover);
            convertView.setTag(holder);

        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        if (list != null) {
            RecommendBookList.RecommendBook item = list.get(position);
            if (!SettingManager.getInstance().isNoneCover()) {
                Glide.with(context).load(item.cover).placeholder(R.mipmap.cover_default) .transform(new GlideRoundTransform(context)).into(holder.ivBookListCover);
            }
            if (item.name != null) {
                holder.tvBookListTitle.setText(item.name);
            }
            if (item.author != null) {
                holder.tvBookAuthor.setText(item.author);
            }
            holder.tvBookListDesc.setText(item.description);

        }
        return convertView;
    }

    static class ViewHolder {
        public TextView tvBookListTitle;
        public TextView tvBookAuthor;
        public TextView tvBookListDesc;
        ImageView ivBookListCover;
    }
}